package 回溯;

import java.math.BigDecimal;
import java.util.*;

/**
 * todo
 *
 * @author songZiHao
 * @version 1.0.0
 * @ClassName 递增子序列491.java
 * @createTime 2022年10月26日 22:22:00
 */
public class 递增子序列491 {
	List<List<Integer>> result = new ArrayList<>();

	public List<List<Integer>> findSubsequences(int[] nums) {
		backTrace(nums, 0, new ArrayList<>());
		return result;
	}

	public void backTrace(int[] nums, int numIndex, List<Integer> curList) {
		//结束条件:到了最后一个了
		if (curList.size() >= 2) {
			result.add(new ArrayList<>(curList));
		}
		//已经用过的数字，因为有可能467 后面是7 变成4677 ，撤销选择之后又变成了467，这样就重复了，所以需要进行一个额外的判断
		HashSet<Integer> used = new HashSet<>();
		//循环
		for (int i = numIndex; i < nums.length; i++) {
			//做选择:如果当前列表的长度小于2，或者最后一个元素大于当前遍历的元素，则继续循环
			if (!curList.isEmpty() && curList.get(curList.size() - 1) > nums[i]) {
				continue;
			}
			if (used.contains(nums[i])) {
				continue;
			}
			curList.add(nums[i]);
			used.add(nums[i]);
			//下一层
			backTrace(nums, i + 1, curList);
			//撤销选择
			curList.remove(curList.size() - 1);
		}
	}

	public static String tidsToStr(String tids) throws Exception {
		String[] tidArr = tids.split("\\|");
		Map<Long, String> tidMap = new HashMap<>();
		for (int i = 0; i < tidArr.length; i++) {
			String tid = tidArr[i].split(":")[0];
			Long key = Long.valueOf(tid.split("-")[1]);
			tidMap.put(key, tid);

		}
		StringBuffer result = new StringBuffer();

		Object[] array = tidMap.keySet().toArray();
		Arrays.sort(array);
		for (int j = 0; j < array.length; j++) {
			String tid = tidMap.get(array[j]);
			result.append(tid);
			if (j < array.length - 1) {
				result.append("|");
			}
		}
		return result.toString();
	}

	public static void main(String[] args) throws Exception {
		System.out.println(new BigDecimal(-67.4).compareTo(new BigDecimal("0")) > 0);
		System.out.println(new BigDecimal(53.4).compareTo(new BigDecimal(48))>0&&new BigDecimal(53.4).compareTo(new BigDecimal(72))<0);
		System.out.println(tidsToStr("221117-166791771082517"));;
	}
}
